uniqueid2 2.2.0
Loading...
Searching...
No Matches
uniqueid2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef UNIQUEID2_H
29#define UNIQUEID2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define UNIQUEID2_REG_DTI 0xE0
74#define UNIQUEID2_REG_CDA 0xC0
75#define UNIQUEID2_REG_SWP 0xA0
76#define UNIQUEID2_REG_UID 0x00
77 // uniqueid2_reg
79
84
89
94#define UNIQUEID2_DTI_DEFAULT 0xB1
95
100#define UNIQUEID2_CDA_C2 0x08
101#define UNIQUEID2_CDA_DAL 0x01
102
107#define UNIQUEID2_SEL_ID_PAGE 0x00
108
113#define UNIQUEID2_BLOCK_SIZE 65536
114#define UNIQUEID2_BLOCK_ADDR_MASK 0xFFFF
115
120#define UNIQUEID2_SWP_BP_QUARTER 0x00
121#define UNIQUEID2_SWP_BP_HALF 0x02
122#define UNIQUEID2_SWP_BP_THREE_QUARTER 0x04
123#define UNIQUEID2_SWP_BP_ALL 0x06
124#define UNIQUEID2_SWP_BP_MASK 0x06
125#define UNIQUEID2_SWP_WPA 0x08
126#define UNIQUEID2_SWP_WPL 0x01
127
132#define UNIQUEID2_UID_LEN 16
133#define UNIQUEID2_UID_HEADER_ST_CODE 0x20
134#define UNIQUEID2_UID_HEADER_BUS_PROTOCOL 0xE0
135#define UNIQUEID2_UID_HEADER_DENSITY 0x12
136
141#define UNIQUEID2_WC_WRITE_ENABLE 0x00
142#define UNIQUEID2_WC_WRITE_DISABLE 0x01
143
148#define UNIQUEID2_PAGE_SIZE 256
149#define UNIQUEID2_ID_PAGE_SIZE 256
150#define UNIQUEID2_MEMORY_SIZE 262144
151#define UNIQUEID2_PAGE_OFFSET_MASK 0xFF
152#define UNIQUEID2_BLOCK_OFFSET 16
153#define UNIQUEID2_BLOCK_MASK 0x03
154
160#define UNIQUEID2_DEVICE_ADDRESS_MEM 0x50
161#define UNIQUEID2_DEVICE_ADDRESS_REG 0x58
162 // uniqueid2_set
164
169
174
179#define UNIQUEID2_MAP_MIKROBUS( cfg, mikrobus ) \
180 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182 cfg.wc = MIKROBUS( mikrobus, MIKROBUS_PWM );
183 // uniqueid2_map // uniqueid2
186
191typedef struct
192{
193 // Output pins
194 digital_out_t wc;
195
196 // Modules
197 i2c_master_t i2c;
198
199 // I2C slave address
201
203
208typedef struct
209{
210 pin_name_t scl;
211 pin_name_t sda;
212 pin_name_t wc;
213
214 uint32_t i2c_speed;
215 uint8_t i2c_address;
216
218
229
235
246
261
275
290err_t uniqueid2_write_memory ( uniqueid2_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len );
291
306err_t uniqueid2_read_memory ( uniqueid2_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
307
322err_t uniqueid2_write_register ( uniqueid2_t *ctx, uint8_t reg, uint8_t data_in );
323
337err_t uniqueid2_read_register ( uniqueid2_t *ctx, uint8_t reg, uint8_t *data_out );
338
353err_t uniqueid2_read_id_page ( uniqueid2_t *ctx, uint8_t offset, uint8_t *data_out, uint16_t len );
354
367err_t uniqueid2_read_uid ( uniqueid2_t *ctx, uint8_t *uid );
368
378void uniqueid2_set_wc_pin ( uniqueid2_t *ctx, uint8_t state );
379
380#ifdef __cplusplus
381}
382#endif
383#endif // UNIQUEID2_H
384 // uniqueid2
386
387// ------------------------------------------------------------------------ END
err_t uniqueid2_read_memory(uniqueid2_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
UNIQUE ID 2 read memory function.
err_t uniqueid2_write_register(uniqueid2_t *ctx, uint8_t reg, uint8_t data_in)
UNIQUE ID 2 write register function.
err_t uniqueid2_read_id_page(uniqueid2_t *ctx, uint8_t offset, uint8_t *data_out, uint16_t len)
UNIQUE ID 2 read ID page function.
void uniqueid2_set_wc_pin(uniqueid2_t *ctx, uint8_t state)
UNIQUE ID 2 set WC pin function.
err_t uniqueid2_read_uid(uniqueid2_t *ctx, uint8_t *uid)
UNIQUE ID 2 read UID function.
err_t uniqueid2_init(uniqueid2_t *ctx, uniqueid2_cfg_t *cfg)
UNIQUE ID 2 initialization function.
err_t uniqueid2_default_cfg(uniqueid2_t *ctx)
UNIQUE ID 2 default configuration function.
err_t uniqueid2_write_memory(uniqueid2_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len)
UNIQUE ID 2 write memory function.
err_t uniqueid2_read_register(uniqueid2_t *ctx, uint8_t reg, uint8_t *data_out)
UNIQUE ID 2 read register function.
void uniqueid2_cfg_setup(uniqueid2_cfg_t *cfg)
UNIQUE ID 2 configuration object setup function.
UNIQUE ID 2 Click configuration object.
Definition uniqueid2.h:209
uint32_t i2c_speed
Definition uniqueid2.h:214
pin_name_t wc
Definition uniqueid2.h:212
pin_name_t scl
Definition uniqueid2.h:210
pin_name_t sda
Definition uniqueid2.h:211
uint8_t i2c_address
Definition uniqueid2.h:215
UNIQUE ID 2 Click context object.
Definition uniqueid2.h:192
digital_out_t wc
Definition uniqueid2.h:194
i2c_master_t i2c
Definition uniqueid2.h:197
uint8_t slave_address
Definition uniqueid2.h:200
uniqueid2_return_value_t
UNIQUE ID 2 Click return value data.
Definition uniqueid2.h:224
@ UNIQUEID2_OK
Definition uniqueid2.h:225
@ UNIQUEID2_ERROR
Definition uniqueid2.h:226